/*
 *  FileName MoonPixelBuffer.h
*/

#ifndef __DEEP_ZOOM_IMAGE_MOONPIXELBUFFER_H__
#define __DEEP_ZOOM_IMAGE_MOONPIXELBUFFER_H__

//#include "stdafx.h"

#include "cairo/cairo.h"
#include "glib/glib-2.0/glib.h"

namespace DeepZoomImage
{
	class MoonPixbuf
	{
	public:
		MoonPixbuf();
		MoonPixbuf (cairo_surface_t *image, bool crc_error);
		virtual ~MoonPixbuf();

		virtual gint GetWidth () ;
		virtual gint GetHeight () ;
		virtual gint GetRowStride () ;
		virtual gint GetNumChannels () ;
		virtual guchar *GetPixels () ;
		virtual gboolean IsPremultiplied () ;		
		
	private:
		gint m_BufWidth;
		gint m_BufHeight;
		gint m_RowStride;
		gint m_NumChannels;
		guchar* m_pPixelsBuf;
		gboolean m_IsPremultiplied;		

		bool crc_error;
		cairo_surface_t *image_surface;

	};

	class MoonPixbufLoader
	{
	public:
		MoonPixbufLoader(const char* imageType);
		MoonPixbufLoader();
		virtual ~MoonPixbufLoader ();

		virtual void Write (const guchar *buffer, int buflen/*, MoonError **error = NULL*/);
		virtual void Close (/*MoonError **error = NULL*/) ;

		virtual MoonPixbuf *GetPixbuf ();
		void SetImageData(unsigned char* dataBuffer,int width,int height,int stride);

	private:
		cairo_status_t ReadFunc (unsigned char *buffer, unsigned int len);
		static cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int len);

		bool crc_error;
		GByteArray *data;
		const char *image_type;
		guint offset;

		MoonPixbuf* pixbuf;

		//JPEG
		unsigned char* data_Buffer;
		int imageWidth;
		int imageHeight;
		int imageStride;
	};
}
#endif /*__DEEP_ZOOM_IMAGE_MOONPIXELBUFFER_H__*/